//
//  ChangePasswordViewController.m
//  Housekeeping
//
//  Created by 辰领科技 on 16/5/25.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ChangePasswordViewController.h"

@interface ChangePasswordViewController ()
<UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UITextField *oldPasswordTextField;
@property (strong, nonatomic) IBOutlet UITextField *PasswordTextFiel;
@property (strong, nonatomic) IBOutlet UITextField *confirmPasswordTextField;
@property (strong, nonatomic) IBOutlet UIButton *button;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
}


- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.scroview.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    
    _button.layer.cornerRadius = 20*VerticalRatio();
    self.oldPasswordTextField.secureTextEntry = YES;
    self.PasswordTextFiel.secureTextEntry = YES;
    self.confirmPasswordTextField.secureTextEntry = YES;
}

#pragma mark - 忘记密码
- (IBAction)forget:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"GetBackPassword"];
    [self presentViewController:page animated:YES completion:nil];
}
#pragma mark - 确认修改
- (IBAction)ConfirmChangeButton:(id)sender {
    if ([self.confirmPasswordTextField.text isEqualToString:self.PasswordTextFiel.text]) {
        [self ChangeThePassword];
    } else {
        [CWHUDTips showTips:@"两次输入密码不一致"];
    }
}


#pragma mark - 返回
- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 修改密码
- (void)ChangeThePassword {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"validateCode"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"password"];
    [dic setObject:[Common md5:self.oldPasswordTextField.text] forKey:@"password_1"];
    [dic setObject:[Common md5:self.PasswordTextFiel.text] forKey:@"password_2"];
    [dic setObject:[Common md5:self.confirmPasswordTextField.text] forKey:@"password_3"];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:F_updatePassword withHttpType:@"POST" withTag:F_F_updatePassword];
}

#pragma mark - 退出登录
- (void)outLogin {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    self.shareApi.delegate=self;
//    [self.shareApi  requestOperationWithDic:dic withPath:JY_exitLogin withHttpType:@"POST" withTag:JY_JY_exitLogin];
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == F_F_updatePassword){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [Common DeleteSingleFile];
            [[AppDelegate sharedAppDelegate]ShowLoginPage];
        }else  {
        }
    }
//        else if (tag == JY_JY_exitLogin) {
//        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
//            
//            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
//            
//        }else {
//            [[CWHUDTips sharedInstance]  showTips:@"退出登录成功"  withStatus:2 dismissAfter:1.5];
//            [Common DeleteSingleFile];
//            [[AppDelegate sharedAppDelegate]  ShowLoginPage];
//            
//        }
//    }

}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
